package com.sghd.fight.robot.action;

import com.sghd.common.socket.client.Client;
import com.sghd.common.socket.core.Message;
import com.sghd.fight.net.SocketEnum;
import com.sghd.fight.robot.core.Robot;
import com.sghd.pojo.fight.game.ConnReq;

/**
 * @author wch
 * @date 2018-07-06 16:57
 * @desc 连接游戏服务器
 **/
public class ConnAction extends AbstractAction {

    @Override
    public Stage stage() {
        return Stage.CONN;
    }

    @Override
    public void action(Robot robot) {
        if (!check(robot)) {
            return;
        }
        Client client = robot.getClient();
        ConnReq req = new ConnReq();
        req.setPlayerId(robot.getRobotId());
        //设置机器人标识
        client.getSession().getContext().setIdentity(req.getPlayerId());
        Message message = Message.valueOf(SocketEnum.CONN, req);
        client.send(message);
    }
}
